package com.trendata.util;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.SimpleTimeZone;
import java.util.TimeZone;

/**
 * 时间操作
 * 
 * @author: HuangXiuXiu Email:243559392@qq.com
 */
public class TimeUtil {

	/**
	 * 获取当前时间
	 * 
	 * @return <code>2015-03-12 10:10:10.234<code>
	 */
	public static Timestamp getCurrent() {
		Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT+8"));
		return new Timestamp(calendar.getTimeInMillis());
	}

	/**
	 * 获取当前的时间，带小时
	 * 
	 * @return <code>2015-03-12 10:00:00.0<code>
	 */
	public static Timestamp getCurrentHour() {
		Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT+8"));
		calendar.set(12, 0);
		calendar.set(13, 0);
		calendar.set(14, 0);
		return new Timestamp(calendar.getTimeInMillis());
	}

	public static String getRfc822DateFormat(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
		sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));

		return sdf.format(date);
	}

}